package com.mareas.web.jsf.view;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mareas.web.service.GenericService;

@Component("listAbstractView")
@ManagedBean
public abstract class ListAbstractView<T> implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -4565552718887546945L;

	@Autowired
	private GenericService genericService;

	private int page = 1;
	private int currentIndex;
	private T edited;
	private Object deleted;

	public abstract T getNew();

	public abstract <T> List<T> getAll();

	public void remove() {
		genericService.remove(deleted);
	}

	public void store() {
		genericService.persist(edited);
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getCurrentIndex() {
		return currentIndex;
	}

	public void setCurrentIndex(int currentIndex) {
		this.currentIndex = currentIndex;
	}

	public T getEdited() {
		return edited;
	}

	public void setEdited(T edited) {
		this.edited = edited;
	}

	public Object getDeleted() {
		return deleted;
	}

	public void setDeleted(Object deleted) {
		this.deleted = deleted;
	}

	public GenericService getGenericService() {
		return genericService;
	}

	public void setGenericService(GenericService genericService) {
		this.genericService = genericService;
	}

}
